<?php
/** Cms_Resource_Staff_Item */
if (!class_exists('Cms_Resource_Staff_Item')) {
    require_once dirname(__FILE__) . '/Staff/Item.php';
}

/**
 * Cms_Resource_Staff
 *
 * @category   Cms
 * @package    Cms_Model_Resource
 */
class Cms_Resource_Staff extends BIS_Model_Resource_Db_Table_Abstract implements Cms_Resource_Staff_Interface
{
    protected $_name = 'staff';
    protected $_primary = 'staffId';
    protected $_rowClass = 'Cms_Resource_Staff_Item';

    public function getStaffById($id)
    {
        return $this->find($id)->current();
    }

    public function getStaffs($data= array())
    {
        
        $select = $this->select();

        if (isset($data['order'])) {
            $select->order($data['order']);
        }

	if (isset($data['page'])) {
		$adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
		$paginator = new Zend_Paginator($adapter);
		$paginator->setItemCountPerPage($data['limit'])
	          	  ->setCurrentPageNumber((int) $data['page']);
		return $paginator;
	}
        
        return $this->fetchAll($select);

    }
    
    public function getStaffReport($fromDate=null, $toDate=null){
    
    	$select = $this->select ();
    
    	if (!empty($fromDate)) {
    		$toDate = (!empty($toDate)) ? $toDate : date('Y-m-d');
    		$select->where("date(addedDate) between '$fromDate' and '$toDate'");
    	}
    
    	$select->order ('addedDate DESC');
    
    	return $this->fetchAll ( $select );
    }
   
}